package cn.java.homework03;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class ClientDemo {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        Socket s = null;
        PrintWriter pw = null;
        BufferedReader br = null;
        ObjectOutputStream oos=null;
        try {
            s = new Socket("127.0.0.1", 9999);
            pw = new PrintWriter(s.getOutputStream(), true);
            br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            oos = new ObjectOutputStream(s.getOutputStream());
            System.out.println(br.readLine());
            String reply1 = in.nextLine();
            pw.println(reply1);
            System.out.println(br.readLine());
            String reply2 = in.nextLine();
            pw.println(reply2);
            String len = br.readLine();
            System.out.println(len);
            if (len.contains("登陆成功")){
                User user = new User(reply1,reply2);
                oos.writeObject(user);
                oos.flush();
                oos.close();
            }


        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                br.close();
                pw.close();
                s.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
